
class Admin::SpecsController < Admin::BaseController

  def index
    @specs = Spec.paginate(page: params[:page] || 1, per_page: params[:per_page] || 15).order("id desc")
  end

  def new
    @spec = Spec.new
  end

  def create
    @spec = Spec.new(params.require(:spec).permit!)
    if @spec.save
      flash[:notice] = "新建规格成功"
      redirect_to admin_specs_path
    else
      render action: :new
    end
  end

  def edit
    @spec = Spec.find params[:id]
    render action: :new
  end

  def update
    @spec = Spec.find params[:id]
    @spec.attributes = params.require(:spec).permit!

    if @spec.save
      flash[:notice] = "修改规格成功"
      redirect_to admin_specs_path
    else
      flash[:notice] = "修改规格失败"
      render action: :new
    end
  end

end
